package com.ruoyi.cust.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cust.domain.CityCarousel;
import com.ruoyi.cust.service.ICityCarouselService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 轮播Controller
 *
 * @author cjq
 * @date 2024-12-06
 */
@Api("轮播")
@RestController
@RequestMapping("/city/carousel")
public class CityCarouselController extends BaseController {
    @Autowired
    private ICityCarouselService cityCarouselService;

    /**
     * 查询轮播列表
     */
    @ApiOperation("查询轮播列表")
    @PreAuthorize("@ss.hasPermi('city:carousel:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityCarousel cityCarousel) {
        startPage();
        List<CityCarousel> list = cityCarouselService.selectCityCarouselList(cityCarousel); return getDataTable(list);
    }

    /**
     * 导出轮播列表
     */
    @ApiOperation("导出轮播列表")
    @PreAuthorize("@ss.hasPermi('city:carousel:export')")
    @Log(title = "轮播", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityCarousel cityCarousel) {
        List<CityCarousel> list = cityCarouselService.selectCityCarouselList(cityCarousel); ExcelUtil<CityCarousel> util = new ExcelUtil<CityCarousel>(CityCarousel. class);
        util.exportExcel(response, list, "轮播数据");
    }

    /**
     * 获取轮播详细信息
     */
    @ApiOperation("获取轮播详细信息")
    @PreAuthorize("@ss.hasPermi('city:carousel:query')")
    @GetMapping(value = "/{carouselId}")
    public AjaxResult getInfo(@PathVariable("carouselId") Long carouselId) {
        return success(cityCarouselService.selectCityCarouselByCarouselId(carouselId));
    }

    /**
     * 新增轮播
     */
    @ApiOperation("新增轮播")
    @PreAuthorize("@ss.hasPermi('city:carousel:add')")
    @Log(title = "轮播", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityCarousel cityCarousel) {
        return toAjax(cityCarouselService.insertCityCarousel(cityCarousel));
    }

    /**
     * 修改轮播
     */
    @ApiOperation("修改轮播")
    @PreAuthorize("@ss.hasPermi('city:carousel:edit')")
    @Log(title = "轮播", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityCarousel cityCarousel) {
        return toAjax(cityCarouselService.updateCityCarousel(cityCarousel));
    }

    /**
     * 删除轮播
     */
    @ApiOperation("删除轮播")
    @PreAuthorize("@ss.hasPermi('city:carousel:remove')")
    @Log(title = "轮播", businessType = BusinessType.DELETE)
    @DeleteMapping("/{carouselIds}")
    public AjaxResult remove(@PathVariable Long[] carouselIds) {
        return toAjax(cityCarouselService.deleteCityCarouselByCarouselIds(carouselIds));
    }
}
